/*
 * CS340 fatboys
 */
package fatboy.hypeerweb;
/* Preston Cowley  */


import java.util.*;

import org.junit.Assert;
import org.junit.Test;


public class TestRemoveSurrogates {

	final static int maxNode = 100;
	
	/**
	 * Sets up a hypeercube for testing.
	 * 
	 * @param cubeSize the cube size
	 * @return handleNode a node that can be used to access the hypeerweb. (The most recently added)
	 */
	public Node testSetup(int cubeSize)
	{		
		Connection testWeb = new Connection();
		String rootMsg = "Node #0";
		Node root = testWeb.addNode(rootMsg);
		
		Node handleNode = root;

		for (Integer i = 1; i <= cubeSize; i++ ) {
			handleNode = (testWeb.addNode("Node #" + i));			
		}
		return handleNode;
	}
	
	/**
	 * test1 for the removeSurrogates method.  Tests to make sure that the node's surrogates are removed, 
	 *   and that no node's edge pointers points to the node.
	 */
	@Test
	public void removeSurrogatesTest1()
	{	
		for (int h = 0; h < maxNode; h++) {
			Node testNode = testSetup(h);
			
			PointerList testPointersCopy = (PointerList) testNode.getPointers().clone();
			
			testNode.removeSurrogates();
			
			Assert.assertTrue(testNode.getPointers().isEmpty());
			//Assert.assertTrue(testNode.getNodeType() == NodeType.INTERIOR_NODE);
			
			for (int j = 0; j < testPointersCopy.size(); j++) {
				PointerList surrogateToEdgeReversePointers = testPointersCopy.get(j).getNode().getPointers();
				for (int k = 0; k < surrogateToEdgeReversePointers.size(); k++) {
					Assert.assertTrue(surrogateToEdgeReversePointers.contains(new EdgePointer(testNode)) == false);
				}
			}	
		}
	}
}
